/**
 * 统一响应格式工具函数
 */

// 成功响应
export const success = (data = null, message = '操作成功', code = 200) => {
  return {
    code,
    message,
    data
  };
};

// 错误响应
export const error = (message = '操作失败', code = 400, data = null) => {
  return {
    code,
    message,
    data
  };
};

// 分页响应
export const paginated = (list = [], pagination = {}, message = '获取成功', code = 200) => {
  return {
    code,
    message,
    data: {
      list,
      pagination
    }
  };
};

// 验证错误响应
export const validationError = (errors = [], message = '参数验证失败', code = 422) => {
  return {
    code,
    message,
    data: {
      errors
    }
  };
};

// 认证错误响应
export const authError = (message = '认证失败', code = 401) => {
  return {
    code,
    message,
    data: null
  };
};

// 权限错误响应
export const permissionError = (message = '权限不足', code = 403) => {
  return {
    code,
    message,
    data: null
  };
};

// 资源不存在响应
export const notFound = (message = '资源不存在', code = 404) => {
  return {
    code,
    message,
    data: null
  };
};

// 服务器错误响应
export const serverError = (message = '服务器内部错误', code = 500) => {
  return {
    code,
    message,
    data: null
  };
};

export default {
  success,
  error,
  paginated,
  validationError,
  authError,
  permissionError,
  notFound,
  serverError
};
